package com.ly.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;

import java.time.LocalDateTime;

@Configuration       //标记配置类，是的springboot容器可以扫描到
@EnableAsync         //开启异步定时任务
@Slf4j
public class MyAsyncTask {

    @Async
    public void publishMsg() {
        try {
            Thread.sleep(5000);
            log.info("异步任务处理完毕"+ LocalDateTime.now());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
